﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using ConstructionBidOnline.Biz;
using ConstructionBidOnline.Common;

public partial class UserProfile : System.Web.UI.Page
{
    #region Types

    public enum LayoutType
    {
        Add,
        Edit,
        Search,
        View
    }

    public SubAdmin objuser;

    #endregion

    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] == null)
            Response.Redirect("sessionexpire.aspx");
        else
        {
            objuser = SubAdmin.GetUserByUserLogin(Session["username"].ToString());
            if (!Page.IsPostBack)
            {
                UpdateData(UpdateDirection.Obj_To_UI);
            }
        }
    }

    #endregion

    #region Button clicks

    #region View Butoon click

    protected void btnview_Click(object sender, ImageClickEventArgs e)
    {
        SetLayout(LayoutType.Edit);
    }

    #endregion

    #region Cancel Button Click

    protected void btncancel_Click(object sender, ImageClickEventArgs e)
    {
        SetLayout(LayoutType.View);
    }

    #endregion

    #region Save Button Click

    protected void btnupdate_Click(object sender, ImageClickEventArgs e)
    {
        UpdateData(UpdateDirection.UI_To_Obj);
        SubAdmin.Update(objuser);
        SetLayout(LayoutType.View);
        UpdateData(UpdateDirection.Obj_To_UI);
    }

    #endregion

    #endregion

    #endregion


    #region Private

    #region SetLayout

    /// <summary>
    /// Configures the UI for the specified 'uiLayoutType'.
    /// </summary>
    protected void SetLayout(LayoutType uiLayoutType)
    {
        switch (uiLayoutType)
        {
            case LayoutType.Add:
            case LayoutType.Edit:

                pnlviewdetails.Visible = false;
                pnleditdetails.Visible = true;
                break;

            case LayoutType.View:
            case LayoutType.Search:

                pnlviewdetails.Visible = true;
                pnleditdetails.Visible = false;
                break;

            default:
                throw new NotImplementedException("The specified LayoutType is not supported in this release.");
        }

        //SetInitialFocus(uiLayoutType);
    }

    #endregion

    #region UpdateDate

    public void UpdateData(UpdateDirection updatedir)
    {
        if (objuser == null)
            return;

        //bool addingNew = (DataSourceEmailLayout.ObjState == BOBase.ObjectState.Added);

        if (updatedir == UpdateDirection.Obj_To_UI)
        {
            //binding lables for view
            lbltitleofcoutesy.Text = objuser.TitleOfCourtesy;
            lblfirstname.Text = objuser.FirstName;
            lbllastname.Text = objuser.LastName;
            lblemailaddress.Text = objuser.EmailAddress;
            lblworkphone.Text = objuser.WorkPhone;
            lblmobilephone.Text = objuser.MobilePhone;
            //binding textboxes for edit
            txttitleofcourtesy.Text = objuser.TitleOfCourtesy;
            txtfirstname.Text = objuser.FirstName;
            txtlastname.Text = objuser.LastName;
            txtemailaddress.Text = objuser.EmailAddress;
            txtworkphone.Text = objuser.WorkPhone;
            txtmobilephone.Text = objuser.MobilePhone;
        }
        else
        {
            objuser.TitleOfCourtesy = txttitleofcourtesy.Text.Trim();
            objuser.FirstName = txtfirstname.Text.Trim();
            objuser.LastName = txtlastname.Text.Trim();
            objuser.EmailAddress = txtemailaddress.Text.Trim();
            objuser.WorkPhone = txtworkphone.Text.Trim();
            objuser.MobilePhone = txtmobilephone.Text.Trim();
        }

    }

    #endregion

    #endregion


    
}
